﻿package mortal.game.view.guild.cellrender
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.mvc.core.*;

    public class GuildSkillListCellRenderer extends GCellRenderer
    {
        private var _skillItem:SkillItem;
        private var _txtSkillName:GTextFiled;
        private var _btnUp:GLoadedButton;
        private var _txtStatus:GTextFiled;
        private var _txtSkillLv:GTextFiled;
        private var _skillShow:SkillInfo;
        private var _nextSkillInfo:SkillInfo;
        private var _skillMax:SkillInfo;
        private var _ckTime:int;

        public function GuildSkillListCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(-20, 78, 280, 1, this, ImagesConst.SplitLine));
            this._skillItem = new SkillItem();
            this._skillItem.x = 20;
            this._skillItem.y = 10;
            this.addChild(this._skillItem);
            this._skillItem.isDragAble = false;
            this._skillItem.isDropAble = false;
            this._skillItem.isThrowAble = false;
            this._skillItem.isShowFreezingEffect = false;
            this._skillItem.isShowLeftTimeEffect = false;
            this._skillItem.isShowToolTip = true;
            this._skillItem.setSize(60, 60);
            this._skillItem.setBg();
            this._skillItem.toolTipMode = SkillItem.TooltipMode_GuildSkill;
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._txtSkillLv = UIFactory.textField("Lv 1/5", this._skillItem.x, this._skillItem.y + this._skillItem.height - 22, this._skillItem.width, 22, this, _loc_1);
            pushUIToDisposeVec(UIFactory.bg(80, 10, 100, 22, this, ImagesConst.TextBg));
            this._txtSkillName = UIFactory.textField("", 90, 10, 80, 22, this, GlobalStyle.textFormatBai.center());
            this._btnUp = UIFactory.gLoadedButton(ImagesConst.Add_upSkin, 180, 13, 16, 16, this);
            this._btnUp.drawNow();
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(71106), 90, 45, 80, 20, this));
            this._txtStatus = UIFactory.textField("", 170, 45, 127, 20, this);
            this._btnUp.configEventListener(MouseEvent.CLICK, this.onBtnUpClickHandler);
            return;
        }// end function

        private function onBtnUpClickHandler(event:MouseEvent) : void
        {
            if (getTimer() - this._ckTime < 350)
            {
                return;
            }
            this._ckTime = getTimer();
            var _loc_2:* = Cache.instance.skill.getSkillBySerialId(this._skillMax.tSkill.series);
            if (_loc_2 && _loc_2.tSkill.skillLevel >= this._skillMax.tSkill.skillLevel)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71107));
                return;
            }
            var _loc_3:* = Cache.instance.guild.selfGuildInfo;
            if (this._nextSkillInfo.tSkill.needGuildContribute > _loc_3.selfInfo.contribution)
            {
                MsgManager.showMouseMsg("" + Language.getString(71108), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (_loc_3.selfInfo.skillTimes >= GuildConst.GuildSkillLearnCount())
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71109));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_school_learn, this._nextSkillInfo.skillId));
            return;
        }// end function

        private function onSelect() : void
        {
            var _loc_2:Array = null;
            var _loc_1:* = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropProp, EPropType._EPropTypeGuildSchool);
            if (_loc_1.length == 0)
            {
                _loc_2 = ItemConfig.instance.getItemByCategoryAndtype(EProp._EPropProp, EPropType._EPropTypeGuildSchool);
                MsgManager.showRollTipsMsg(_loc_2[0].name + Language.getString(71110));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_school_learn, this._nextSkillInfo.skillId));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._skillShow = null;
            this._nextSkillInfo = null;
            this._skillMax = null;
            this._skillItem.dispose(param1);
            this._txtSkillName.dispose(param1);
            this._btnUp.dispose(param1);
            this._txtStatus.dispose(param1);
            this._skillItem = null;
            this._txtSkillName = null;
            this._btnUp = null;
            this._txtStatus = null;
            this._txtSkillLv.dispose(param1);
            this._txtSkillLv = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            var _loc_2:* = Cache.instance.guild.selfGuildInfo;
            var _loc_3:Boolean = true;
            var _loc_4:Boolean = true;
            this._skillMax = new SkillInfo();
            this._skillMax.tSkill = SkillConfig.instance.getInfoById(param1.data as int);
            this._skillShow = new SkillInfo();
            this._skillShow.learned = true;
            var _loc_5:* = Cache.instance.skill.getSkillBySerialId(this._skillMax.tSkill.series);
            if (_loc_5 == null)
            {
                this._skillShow.tSkill = SkillConfig.instance.getFirstSkillBySerialId(this._skillMax.tSkill.series);
                this._skillShow.learned = false;
                this._nextSkillInfo = this._skillShow;
            }
            else if (_loc_5.tSkill.skillLevel >= this._skillMax.tSkill.skillLevel)
            {
                this._nextSkillInfo = _loc_5;
                this._skillShow.tSkill = SkillConfig.instance.getSkillByLevel(_loc_5.tSkill.series, _loc_5.tSkill.skillLevel);
                this._btnUp.filters = null;
                _loc_3 = false;
            }
            else
            {
                this._nextSkillInfo = new SkillInfo();
                this._nextSkillInfo.tSkill = SkillConfig.instance.getSkillByLevel(_loc_5.tSkill.series, (_loc_5.tSkill.skillLevel + 1));
                this._skillShow.tSkill = SkillConfig.instance.getSkillByLevel(_loc_5.tSkill.series, _loc_5.tSkill.skillLevel);
            }
            this._skillItem.setSkillInfo(this._skillShow);
            var _loc_6:* = this._nextSkillInfo.tSkill.needGuildContribute.toString();
            if (this._nextSkillInfo.tSkill.needGuildContribute > _loc_2.selfInfo.contribution)
            {
                this._btnUp.filters = null;
                _loc_6 = HTMLUtil.addColor(_loc_6, GlobalStyle.colorHong);
                _loc_4 = false;
            }
            this._txtStatus.htmlText = _loc_6;
            if (_loc_4 && _loc_3)
            {
                this._btnUp.filters = [FilterConst.itemChooseFilter];
            }
            else
            {
                this._btnUp.filters = null;
            }
            this._txtSkillName.htmlText = this._skillShow.skillName;
            var _loc_7:String = "Lv0/";
            if (_loc_5)
            {
                _loc_7 = "Lv" + _loc_5.skillLevel + "/";
            }
            this._txtSkillLv.text = _loc_7 + this._skillMax.skillLevel.toString();
            return;
        }// end function

        override public function get data() : Object
        {
            return super.data;
        }// end function

        override public function set label(param1:String) : void
        {
            return;
        }// end function

    }
}
